var commentClassifyId='',commentClassifyName='',commentClassList=[];

layui.use(['form', 'xmSelect', 'upload', 'laydate'], function () {
    var form = layui.form;
    laydate = layui.laydate;

    $('#mySelect').attr("disabled",true);
    AjaxGet( '/jazUserCommentDescription/getCommentType'  ).then(function (response){
        if(response.code=='0'){
            //设置select
            $('#mySelect').empty();
            $('#mySelect').append($('<option>', {
                value: '',
                text: '请选择评价类型'
            }))
            commentClassList=response.data
            response.data.forEach(item=>{
                $('#mySelect').append($('<option>', {
                    value: item.id,
                    text: item.commentTypeName,
                    selected:$('#commentClassifyId').val()==item.id
                }))
            })
            $('#mySelect').attr("disabled",false);
            form.render('select');
            selectInput($('#mySelect'),10)
        }
    }).catch(error => {
        layer.msg(error.msg)
    })



    form.on('select(demo-select-filter)', function(data){
        commentClassifyId= data.value
        let myItem=commentClassList.find(item=>item.id=data.value)
        commentClassifyName= myItem.commentTypeName
    });

    //提交事件
    form.on('submit(submit)', function (data) {
        console.log(data.field)
        let params=data.field
        params.labelStatus=params.labelStatus=='on'?0:1
        params.commentClassifyId=commentClassifyId
        // params.commentClassifyName=commentClassifyName

        if ($('#infoType').val() == 'edit') {
            params.id = $('#userId').val()
        }
        AjaxPost($('#infoType').val()=='add'?'/jazUserCommentDescription/save':'/jazUserCommentDescription/update', params).then(function (response) {
            parent.layer.msg("操作成功");
            var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
            parent.layer.close(index);
            parent.load();
        }).catch(error => {
            layer.msg(error.msg)
        })

    });

});

